package org.ax.controller.device;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.ax.data.Result;
import org.ax.pojo.device.Device;
import org.ax.pojo.device.DeviceType;
import org.ax.service.device.DeviceService;
import org.ax.service.device.DeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-28-23:16
 */
@RestController
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    DeviceService deviceService;
    @Autowired
    Result result;
    @GetMapping("/list")
    public Result search(String deviceTypeId,@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "6") int limit){
        Page<Device> devicePage = deviceService.searchDevices(new Page(page, limit), deviceTypeId);
        result.setData(devicePage.getRecords());
        result.setCount(devicePage.getTotal());
        return result;
    }
    @PostMapping("/add")
    public Result add(Device device){
        result.setMsg(deviceService.addDevice(device)?"添加成功":"添加失败");
        return result;

    }
    @PostMapping("/update")
    public Result update(Device device){
        result.setMsg(deviceService.addDevice(device)?"修改成功":"修改失败");
        return result;

    }
    @GetMapping("/patchDel")
    public Result patchDel(String[] ids){
        result.setMsg(deviceService.deletesDevice(ids)?"批量删除成功":"批量删除失败");
        return result;
    }
    @GetMapping("/deviceResultList")
    public Result deviceResultList(){
        result.setData(deviceService.findDevices());
        return result;
    }
}
